﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using YiSha.Service.QixingManage;
using YiSha.Util;
using YiSha.Util.Model;

namespace YiSha.Business.AutoJob.Job
{
    public class GroupChatUpJob : IJobTask
    {
        private GroupChatJoinWayService groupChatJoinWayService = new GroupChatJoinWayService();

        public async Task<TData> Start()
        {
            TData obj = new TData();
            var lsit=groupChatJoinWayService.GetList(null).Result;
            var url = GlobalContext.SystemConfig.WebApiSite + "/WeCom/UpdateContactWay";
            foreach (var item in lsit)
            {
                //判断时间
                if (item.lasttime.AddDays(5)>DateTime.Now)
                {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic.Add("chat_id", item.chat_id);
                    dic.Add("config_id", item.config_id);
                    if (item.auto_create_room == 1)
                    {
                        dic.Add("room_base_id", item.room_base_id);
                        dic.Add("room_base_id", item.room_base_name);
                    }

                    dic.Add("scene", item.scene);
                    dic.Add("remark", item.remark);
                    var postjson = System.Text.Json.JsonSerializer.Serialize(dic);
                    var res=HttpHelper.Post(postjson, url);
                    //日志记录，方便查看
                    LogHelper.Info(res);
                }
            }
            obj.Tag = 1;
            obj.Message = "同步群二维码";
            return obj;
        }
    }
}
